<template>
	<view class="wrap">
		<view style="background-color: #FFFFFF; position: sticky; top: 0;z-index: 2;">

		<!-- 	<u-tabs-swiper :list="tabs" ref="tabs" :current="current" keyName="name" :is-scroll="false" @change="change"
				activeColor="#20C3AA" inactiveColor="#606266" bold="false">
			</u-tabs-swiper> -->
			<view class='box-title'>
				<view v-for="(item,index) in tabs":key= 'index' class='title' :class="selectIndex==index?'title1':''" @click='selectText(index)'>
					<text>{{item.name}}</text>
				</view>
			</view>
			<!-- 
			 :activeItemStyle="{
			 		  color:'#20C3AA',
			 		  fontWeight:'bold',
			 		  transform:'scal(1.05)'
			 	  }" :style="{
			 		  color:'#606266',
			 		  transform:'scal(1)'
			 	  }"-->

		</view>

		<swiper class="swiper-box" :current="swiperCurrent" >
			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom(0)">
					<view class="page-box" v-if="insuranceList.length > 0">

						<view class="box" v-for="(item, index) in insuranceList" :key="index">

							<view style="display:flex; justify-content: space-between;align-items: center;margin-bottom: 32upx;">

								<text class="car-title">
									车牌号：{{filterNull(item.carNo)}}
								</text>

								<view class='car-value'>
									{{filterNull(item.maintenanceStateStr)}}
								</view>
							</view>

							<u-line color="#efefef" dashed margin="0 0 15px"></u-line>

							<view class="text-line1">
								<text class="text-name">车型:</text>
								<text class="text-value">{{filterNull(item.brandSeriesModelName)}}</text>
							</view>


							<view class="text-line1">
								<view>
									<text class="text-name">交强险到期时间:</text>
									<text class="text-value">{{filterNull(item.compulsoryEndTime)}}</text>
								</view>
								<view>
									<text class="text-warn"
										:class="{'text-warn-orange':item.jqPolicyPrescriptionStr == '暂无保险'}">{{item.jqPolicyPrescriptionStr != null ? item.jqPolicyPrescriptionStr : ''}}</text>
								</view>
							</view>
							
							<view class="text-line1">
								<view>
									<text class="text-name">承运险到期时间:</text>
									<text class="text-value">{{filterNull(item.carrierEndTime)}}</text>
								</view>
								<view>
									<text class="text-warn"
										:class="{'text-warn-orange':item.cyPolicyPrescriptionStr == '暂无保险'}">{{item.cyPolicyPrescriptionStr != null ? item.cyPolicyPrescriptionStr : ''}}</text>
								</view>
							</view>

							<view class="text-line1">
								<view>
									<text class="text-name">商业险到期时间:</text>
									<text class="text-value">{{filterNull(item.commercialEndTime)}}</text>
								</view>
							
								<view>
									<text class="text-warn"
										:class="{'text-warn-orange':item.syPolicyPrescriptionStr == '暂无保险'}">{{item.syPolicyPrescriptionStr != null ? item.syPolicyPrescriptionStr : ''}}</text>
								</view>
								
							</view>

							<view style='display: flex;flex-direction: column;align-items: flex-end;'>
								<!-- <view class="btn-detail" @click="goYearCheck(item)">
									年 检
								</view> -->

								<view 
									style="font-size:24upx;margin-bottom:10upx;color: #E93131;background-color:#FFFFFF;white-space: nowrap;float: right;">
									{{item.promptInfor ? item.promptInfor:''}}
								</view>

								<view style='float:right' class="btn-detail1" @click="insuranceItemClick(item)">
									详 情
								</view>
							</view>




						</view>

						<u-loadmore :status="loadStatus[0]" @loadmore="reachBottom(0)"></u-loadmore>
					</view>

					<no-data v-if="insuranceList.length === 0"></no-data>

				</scroll-view>
			</swiper-item>

			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom(1)">
					<view class="page-box" v-if="inspectionList.length > 0">

						<view class="box" v-for="(item, index) in inspectionList" :key="index">

							<view style="display:flex; justify-content: space-between;align-items: center;margin-bottom: 32upx;">

								<text class="car-title">
									车牌号：{{filterNull(item.carNo)}}
								</text>

								<view class='car-value'>
									{{filterNull(item.prompt)}}
								</view>
							</view>

							<u-line color="#efefef" dashed margin="0 0 15px"></u-line>

							<view class="text-line1">
								<text class="text-name">品牌/车系/车型:</text>
								<text class="text-value">{{filterNull(item.brandSeriesModelName)}}</text>
							</view>

							<view class="text-line1">
								<view>
									<text class="text-name">年检到期时间:</text>
									<text class="text-value">{{filterNull(item.nextInspectionTime)}}</text>
								</view>
								<view>
									<text
										class="text-warn">{{item.inspectionDatePrompt != null ? item.inspectionDatePrompt : ''}}</text>
									<!-- :class="{'text-warn-orange': -1 !=item.inspectionDatePrompt.indexOf('小时')}" -->
								</view>
							
							</view>

							<view style='display: flex;flex-direction: column;align-items: flex-end;'>
								<!-- <view class="btn-detail" @click="goYearCheck(item)">
									年 检
								</view> -->

								<view 
									style="font-size:24upx;margin-bottom:10upx;color:#E93131;background-color:#FFFFFF;white-space: nowrap;">
									{{item.promptInfor ? item.promptInfor:''}}
								</view>

								<view class="btn-detail1" @click="inspectionItemClick(item)">
									详 情
								</view>
							</view>

						</view>

						<u-loadmore :status="loadStatus[1]" @loadmore="reachBottom(1)"></u-loadmore>
					</view>

					<no-data v-if="inspectionList.length === 0"></no-data>

				</scroll-view>
			</swiper-item>

			<swiper-item class="swiper-item">
				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom(2)">
					<view class="page-box" v-if="maintainList.length > 0">

						<view class="box" v-for="(item, index) in maintainList" :key="index">

							<view style="display:flex; justify-content: space-between;align-items: center;margin-bottom: 32upx;">

								<text class="car-title">
									车牌号：{{filterNull(item.carNo)}}
								</text>

								<view class='car-value'>
									{{filterNull(item.maintenanceStateStr)}}
								</view>
							</view>

							<u-line color="#efefef" dashed margin="0 0 15px"></u-line>

							<view class="text-line1">
								<text class="text-name">品牌/车系/车型:</text>
								<text class="text-value">{{filterNull(item.brandSeriesModelName)}}</text>
							</view>

							<view class="text-line1">
								<view>
									<text class="text-name">下次保养公里数:</text>
									<text class="text-value">{{filterNull(item.nextMile)}}</text>
								</view>
								<view>
									<text class="text-warn">{{item.remindMile != null ? item.remindMile : ''}}</text>
								</view>
								
							</view>

							<view class="text-line1">
								<view>
									<text class="text-name">下次保养时间:</text>
									<text class="text-value">{{filterNull(item.nextDate)}}</text>
								</view>
								<view>
									<text class="text-warn">{{item.prompt != null ? item.prompt : ''}}</text>
								</view>
								
							</view>

						    <view style='display: flex;flex-direction: column;align-items: flex-end;'>
								<!-- <view class="btn-detail" @click="goMaintain(item)">
									保 养
								</view> -->

								<view 
									style="font-size:24upx;margin-bottom:10upx;color: #E93131;background-color:#FFFFFF;white-space: nowrap;">
									{{item.promptInfor ? item.promptInfor:''}}
								</view>

								<view class="btn-detail1" @click="maintainItemClick(item)">
									详 情
								</view>
							</view>

						</view>

						<u-loadmore :status="loadStatus[2]" @loadmore="reachBottom(2)"></u-loadmore>
					</view>

					<no-data v-if="maintainList.length === 0"></no-data>

				</scroll-view>
			</swiper-item>
		</swiper>


	</view>
</template>

<script>
	import {
		maintenanceremindcount,
		insurancelist,
		inspectionlist,
		maintenancelist,
	} from '../../../../common/api.js';

	export default {
		data() {
			return {
				tabs: [{
						name: '保险',
						value:0,
					},
					{
						name: '年检',
						value:0,
					},
					{
						name: '保养',
						value:0,
					}
				],
				current: 0,
				swiperCurrent: 0,
				insuranceList: [],
				inspectionList: [],
				maintainList: [],
				dx: 0,
				loadStatus: ['loadmore', 'loadmore', 'loadmore'],
				pageNo: [1, 1, 1],
				pageSize: 10,
				selectIndex:0,
			}
		},
		methods: {
			// tab栏切换
            selectText(index){
				this.swiperCurrent = index;
				this.selectIndex = index
				this.pageNo=[1, 1, 1]
				switch (index) {
					case 0:
						this.getInsuranceData();
						break;
					case 1:
						this.getInspectionData();
						break;
					case 2:
						this.getMaintainData();
						break;
				}
			},
			change(index) {
				this.swiperCurrent = index;	
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},

			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},

			getCount() {
				maintenanceremindcount().then(res => {
					this.tabs[0].name = `保险(${res.insuranceCount})`;
					this.tabs[1].name = `年检(${res.inspectionCount})`;
					this.tabs[2].name = `保养(${res.maintenanceCount})`;
				})
			},

			getInsuranceData() {
				insurancelist({
					params: {
						pageNo: this.pageNo[0],
						pageSize: this.pageSize
					}
				}).then(res => {
					if (this.pageNo[0] == 1) {
						this.insuranceList = [];
						this.pageNo[0]++;

						this.loadStatus[0] = 'loadmore';

					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo[0]++;

							this.loadStatus[0] = 'loadmore';
						} else {
							this.loadStatus[0] = 'nomore';
						}
					}

					this.insuranceList = this.insuranceList.concat(res);
				})
			},

			getInspectionData() {
				inspectionlist({
					params: {
						pageNo: this.pageNo[1],
						pageSize: this.pageSize
					}
				}).then(res => {
					if (this.pageNo[1] == 1) {
						this.inspectionList = [];
						this.pageNo[1]++;

						this.loadStatus[1] = 'loadmore';

					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo[1]++;

							this.loadStatus[1] = 'loadmore';
						} else {
							this.loadStatus[1] = 'nomore';
						}
					}

					this.inspectionList = this.inspectionList.concat(res);
				})
			},

			getMaintainData() {
				maintenancelist({
					params: {
						pageNo: this.pageNo[2],
						pageSize: this.pageSize
					}
				}).then(res => {
					if (this.pageNo[2] == 1) {
						this.maintainList = [];
						this.pageNo[2]++;

						this.loadStatus[2] = 'loadmore';

					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo[2]++;

							this.loadStatus[2] = 'loadmore';
						} else {
							this.loadStatus[2] = 'nomore';
						}
					}

					this.maintainList = this.maintainList.concat(res);
				})
			},

			insuranceItemClick(item) {
				// getApp().globalData.vehicleData = item;
				uni.navigateTo({
					url: './maintainDetail?type=0&carId=' + item.carId
				})
			},

			inspectionItemClick(item) {
				// getApp().globalData.vehicleData = item;
				uni.navigateTo({
					url: './maintainDetail?type=1&carId=' + item.carId
				})
			},

			maintainItemClick(item) {
				// getApp().globalData.vehicleData = item;
				uni.navigateTo({
					url: './maintainDetail?type=2&carId=' + item.carId
				})
			},

			reachBottom(type) {
				this.loadStatus[type] = 'loading';

				switch (type) {
					case 0:
						this.getInsuranceData();
						break;
					case 1:
						this.getInspectionData();
						break;
					case 2:
						this.getMaintainData();
						break;
				}
			}

		},

		onLoad() {
			this.getCount();
			this.getInsuranceData();
			this.getInspectionData();
			this.getMaintainData();
		}

	}
</script>

<style lang="scss" scoped>
	.car-value{
		color:#173B42;
		background-color:#FFFFFF;
		white-space: nowrap;
		font-size: 28upx;
	}
	.text-line1{
		margin-bottom:16upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.box{
		padding:32upx;
		background-color: #ffffff;
		border-radius: 8upx;
		margin-bottom: 16upx;
	}
	.car-title{
		font-size: 32upx;
		color:#000000;
		font-weight: bold;
	}
	.text-name{
		font-size: 24upx;
		color:#666666
	}
	.wrap {
		@include flex(column);
		height: calc(100vh - var(--window-top));
		padding: 32upx;
	}
	.box-title{
		width: 100%;
		display: flex;
		justify-content: space-around;
		align-items: center;
		.title{
			text-align: center;
			text{
				width:200upx;
				font-size: 28upx;
				color:#000000;
			}
		}
		.title1{
			background-color: #173B42 ;
			color:#ffffff;
			border-radius: 8upx;
			text{
				color:#ffffff;
			}
		}
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
		margin-top:24upx;
	}

	.item {
		display: flex;
		flex-direction: column;
		background-color: white;
		border-radius: 8upx;
		margin: 10upx 20upx;
		padding-bottom: 10upx;
		.title {
			width: 100%;
			height: 64upx;
			line-height: 64upx;
			font-size: 28upx;
			color: $black33;
			margin-left: 20upx;
		}
	}
	.title {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 28upx;
		color: $black33;
		margin-left: 20upx;
	}

	

	.text-warn {
		font-size: 24upx;
		color: #FF6A15;
		margin-right: 20upx;
	}

	.text-warn-orange {
		color: $yellowffc;
	}

	.btn-detail1 {
		width: 120upx;
		height: 64upx;
		border-radius: 4upx;
		color: #173B42;
		text-align: center;
		font-size: 28upx;
		line-height: 64upx;
		margin: 10upx 20upx 10upx;
		border:2upx solid #173B42;
	}

	.noData {
		@include flex;
		justify-content: center;
		margin-top: 50upx;
	}
</style>
